<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <span id="location"></span>
    <input type="button" value="显示位置" onclick="getGeolocation()">
    <script>
        var x=document.getElementById("location");
        function getGeolocation(){
            if(navigator.geolocation){
                //getCurrentPosition()用来获取用户的位置
                navigator.geolocation.getCurrentPosition(res=>{
                    console.log(res)
                });
            }else{
                x.innerHTML="该浏览器不支持获取地理位置！";
            }
        }
    </script>
</body>
</html>